import pandas as pd
from sklearn.preprocessing import MinMaxScaler
timestamp = 30
import numpy as np
class StockNetDataset(object):
    '''
    文件格式： Date,Open,High,Low,Close,Adj Close,Volume
    '''
    __corpus_name__ = "stock_net_dataset"

    @classmethod
    def load_data(self,file_name):
        df = pd.read_csv(file_name)

        minmax = MinMaxScaler()
        minmax.fit(df.iloc[:, 4:5].astype('float32'))  # Close index
        df_log = minmax.transform(df.iloc[:, 1:5].astype('float32'))  # Close index
        df_log = pd.DataFrame(df_log)
        df_log.head()

        max_index = df_log.shape[0] - timestamp


        train_x = []
        train_y = []
        for k in range(0, max_index - 1):
            index = min(k + timestamp, df_log.shape[0] - 1)
            batch_x = df_log.iloc[k: index, :].values
            batch_y = df_log.iloc[index: index + 1, 3:].values
            train_x.append(batch_x)
            train_y.append(batch_y)



        return np.array(train_x),np.array(train_y)





